package org.oy.sealogger.common;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * A singleton wrapper for Messages.properties
 * @author riku
 *
 */
public class Messages {

	private static Properties messages;
	private static Messages singleton;
	private static Logger log;
	
	private Messages() {
		try {
			messages.load(this.getClass().getResourceAsStream("Messages.properties"));
		} catch (IOException e) {
			log.error(e);
		}
	}
	
	/**
	 * Initialises the Messages class by constructing the singleton Message object and loading
	 * in the properties file.
	 */
	protected static void init() {
		log = Config.getLogger();
		messages = new Properties();
		singleton = new Messages();		
	}
	
	/**
	 * Get a message
	 * @param key Message identifier
	 * @return Message or null if nothing can be found with the provided key
	 */
	public static String getMessage(String key) {
		return messages.getProperty(key);
	}
	
	/**
	 * Get the singleton object of this class
	 * @return
	 */
	public Messages getInstance() {
		return singleton;
	}
}
